﻿using TimerTask.Common.Utils;
using TimerTask.Dal;
using TimerTask.Model.Common;
using TimerTask.Model.Entity;

namespace TimerTask.Bll
{
    public class AccountBll
    {
        private readonly SysUserDal _userDal = new SysUserDal();

        /// <summary>
        /// 登录， 成功返回token
        /// author:肖阳
        /// 2016-10-22 09:44:00
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public MsgResult<string> Login(string userName, string pwd)
        {
            userName = userName?.Trim();
            SysUser user = _userDal.FindBy(userName);
            string resultData = string.Empty;
            if (user != null && user.Pwd.Equals(Md5Util.GetMd5(pwd, AppConfig.Instance.Salt)) && user.UserStatus == SysUserStatus.Normal)
            {
                resultData = Md5Util.GetMd5(userName, AppConfig.Instance.Salt);
                return MsgResult<string>.Success(resultData);
            }
            return MsgResult<string>.Error("登录失败");
        }
    }
}
